var param = {}, formId = 'queryForm', url = "/openx/logistics/logisticsListService/listLogistics"

var days = 7;
$.openx.query = function () {
    var createStartTime = new Date($("#createStartTime").val().replace(/\-/g, "\/"));
    var createEndTime = new Date($("#createEndTime").val().replace(/\-/g, "\/"));
    if (createStartTime > createEndTime) {
        layer.msg('开始时间不能大于结束时间！');
        return false;
    }
    var orderCode = $("input[name='orderCode']").val();
    var waybillCode = $("input[name='waybillCode']").val();
    //查询验证时间区间
    if (orderCode.trim() === '' && waybillCode.trim() === '') {
        if (isNaN(createStartTime.getTime())) {
            layer.msg('开始时间不能为空！');
            return false;
        }
        if (isNaN(createEndTime.getTime())) {
            layer.msg('结束时间不能为空！');
            return false;
        }
        if (createStartTime.setDate(createStartTime.getDate() + days) < createEndTime) {
            layer.msg('选择的时间区间必须在' + days + '天以内');
            return false;
        }
    }
    var data = $.openx.getJsonObj(formId);
    param.bean = data;
    $.openx.tableRefresh(url, param);
}

function dateFormat(value) {
    return !value ? "-" : new Date(value).format("yyyy-MM-dd hh:mm")
}

// 点击订单状态查询订单信息
var previousObj = $("button[name='deliveryStatus']")[0];
$("button[name='deliveryStatus']").on('click', function (e) {
    var $this = e.currentTarget;
    $("input[name='deliveryStatus']").val($this.value);
    if (previousObj != $this) {
        $($this).find('i').addClass("glyphicon glyphicon-ok-sign")
        $(previousObj).find('i').removeClass('glyphicon glyphicon-ok-sign');
    }
    previousObj = $this;
    $.openx.query();
})

layui.use('laydate', function () {
    var laydate = layui.laydate;
    document.getElementById('createStartTime').value = laydate.now() + ' 00:00:00';
    document.getElementById('createEndTime').value = laydate.now() + ' 23:59:59';

    var data = $.openx.getJsonObj(formId);
    param.bean = data;
    $.openx.initTable("table", url, param);

});

function resetForm(){
    $('#queryForm')[0].reset();
    var laydate = layui.laydate;
    console.log(laydate.now().split(' ')[0]);
    document.getElementById('createStartTime').value = laydate.now().split(' ')[0] + ' 00:00:00';
    document.getElementById('createEndTime').value = laydate.now().split(' ')[0] + ' 23:59:59';

    var data = $.openx.getJsonObj(formId);
    param.bean = data;
    $.openx.initTable("table", url, param);
    $.openx.query();
}

function showDeliveryDetail(row) {
    var html = $.openx.innerHtml('deliveryDetailTpl');
    $X("/logistics/logisticsListService", "getDeliveryDetail").callx({
        deliveryCode: row.deliveryCode,
        onResult: function (result) {
            layer.closeAll('loading')
            result.deliveryTime = new Date(result.deliveryTime).format("yyyy-MM-dd hh:mm");
            laytpl($.openx.innerHtml('deliveryDetailTpl')).render(result, function (html) {
                $.openx.openLayer(null, '配送详情', html, true);
            });
        },
        onError: function (error) {

        }
    });
}

function showNodeInfo(row) {
    $X("/logistics/logisticsListService", "getDeliveryTask").callx({
        orderCode: row.orderCode,
        onResult: function (result) {
            layer.closeAll('loading')
            laytpl($.openx.innerHtml('logisticsInfotpl')).render(result, function (html) {
                $.openx.openLayer(null, '物流跟踪详情', html, true);
            });
        },
        onError: function (error) {
            var res = JSON.parse(error);
            layer.msg(res.message)
        }
    });
}

//打印物流信息
function printLogisticsInfo(row) {
    window.setTimeout(function () {
        $.openx.tableRefresh(null, null, true);
    }, 2000);
    if (row.logisticsId === 'YTO') {
        window.open('../../html/logistics/print/printYT.html?deliveryCode=' + row.deliveryCode + '&logisticsId=' + row.logisticsId);
    } else if (row.logisticsId === 'SF') {
        window.open('../../html/logistics/print/printSF.html?deliveryCode=' + row.deliveryCode + '&logisticsId=' + row.logisticsId);
    } else if (row.logisticsId === 'ZTO') {
        window.open('../../html/logistics/print/printZTO.html?deliveryCode=' + row.deliveryCode + '&logisticsId=' + row.logisticsId);
    }

    setTimeout(function () {
        $.openx.tableRefresh(null, null, true)
    }, 2000)

}


function markFinished(row) {
    $.openx.confirm('确认手动标记配送完成？', function () {
        $X("/logistics/logisticsListService", "updateStatus").callx({
            deliveryCode: row.deliveryCode,
            deliveryStatus: "DELIVERY_FINISHED",
            onResult: function (result) {
                layer.closeAll()
                $.openx.tableRefresh(null, null, true);
                if (result == 0) {
                    layer.msg("更新失败");
                }
            },
            onError: function (error) {
                layer.msg(error.msg);
            }
        });
    })
}

function markCanceled(row) {
    $.openx.confirm('确认手动标记配送异常？', function () {
        $X("/logistics/logisticsListService", "updateStatus").callx({
            deliveryCode: row.deliveryCode,
            deliveryStatus: "DELIVERY_EXCEPTION",
            onResult: function (result) {
                layer.closeAll()
                $.openx.tableRefresh(null, null, true);
                if (result == 0) {
                    layer.msg("更新失败");
                }
            },
            onError: function (error) {
                layer.msg(error.msg);
            }
        });
    })
}


//取消发货操作
function cancelDeliveryTask(row) {
    $.openx.confirm('是否确认取消配送？取消后可重新配送！', function () {
        $X("/logistics/operateService", "cancelDeliveryTask").callx({
            orderCode: row.orderCode,
            orderCancel: 'N',
            onResult: function (result) {
                layer.msg("取消成功");
                setTimeout(function () {
                    $.openx.tableRefresh(null, null, true)
                }, 3000)
            },
            onError: function (error) {
                layer.alert(error.msg);
            }
        });
    });
}


function showLogisticsDetail(value, row) {
    var escapeRow = $.openx.escapeHtml(JSON.stringify(row));
    return "<a href=\'javascript:void(0)\' title='\物流详情\' style = '\color:#000000;text-decoration:underline;\' onclick =\'javascript:showDeliveryDetail(" + escapeRow + ")\'><b>" + row.orderCode + "</b><a>";
}


function orderIsCancelFormat(value, row) {
    if (value === 'Y') {
        return '<font color="red">订单已被拒收，退货中状态，无须重新配送</font>'
    }
    return '-'
}

function listPartner(row) {
    $X("/logistics/logisticsListService", "listPartnerByOrderCode").callx({
        orderCode: row.orderCode,
        onResult: function (result) {
            laytpl($.openx.innerHtml('listPartnerTpl')).render(result, function (html) {
                $.openx.openLayer(['500','200'], '确认配送方式', html, true, function () {
                    var partnerId = $('input:radio[name="partnerId"]:checked').val();
                    if (partnerId) {
                        $X("/logistics/operateService", "reDelivery").callx({
                            orderCode: row.orderCode,
                            partnerId: partnerId,
                            onResult: function (result) {
                                $.openx.tableRefresh(null, null, true)
                                layer.closeAll()
                            },
                            onError: function (error) {
                                layer.msg(error.msg);
                            }
                        });
                    }
                });
            });
        },
        onError: function (error) {
            layer.msg(error.msg);
        }
    });
}


function modifyAddress(row){
	
	 $X("/logistics/operateService", "queryReceiver").callx({
		orderCode:row.orderCode,
		onResult: function (data) {
            if (data) {
            	var updateForm = "modifyAddressForm";
                var innerHtml = $.openx.innerHtml('modifyAddressDialog');
            	laytpl(innerHtml).render(row, function (html) {
                    $.openx.openLayer(['800', '400'], '修改收货地址信息', html, false, function () {
                        if ($.openx.validation(updateForm)) {
                            //获取表单数据
                            $("#deliveryAreaCode").val($("#add_city option:selected").val());

                            var deliveryProvinceName = $("#add_province option:selected").text();
                            $("#add_provinceId").val(deliveryProvinceName)
                            var deliveryCityName = $("#add_city option:selected").text();
                            $("#add_cityId").val(deliveryCityName)

                            var receiveProvinceName = $("#receive_add_province option:selected").text();
                            $("#add_receive_provinceId").val(receiveProvinceName)
                            var receiveCityName = $("#receive_add_city option:selected").text();
                            $("#add_receive_cityId").val(receiveCityName)
                            var receiveDistrictName = $("#receive_add_district option:selected").text();
                            $("#add_receive_districtId").val(receiveDistrictName)

                            var receiver = new Object();
                            var param = $.openx.getJsonObj(updateForm);
                            $X("/logistics/operateService", "modifyReceiverAddress").callx({
                            	receiver: param,
                                orderCode:param.orderCode,
                                onResult: function (data) {
                                    if (data) {
                                        $.openx.tableRefresh(null, null, true);
                                        layer.closeAll();
                                        layer.msg("更新成功");
                                    }
                                },
                                onError: function (error) {
                                    var res = JSON.parse(error);
                                    layer.msg(res.message)
                                }
                            });

                        }
                    });
                });
//                $.ajaxSetup({async: false});
                initAreaSelect("receive_add_province", "receive_add_city", "receive_add_district");
                $("#name").val(data.name);
                $("#phone").val(data.phone);
                $("#detailAddress").val(data.detailAddress);
                $('#receive_add_province option').filter(function () {
                    return $(this).html() == data.provinceName; }).attr("selected", true);
                $('#receive_add_province').trigger("change");
                $('#receive_add_city option').filter(function () {
                    return $(this).html() == data.cityName; }).attr("selected", true);
                $('#receive_add_city').trigger("change");
                $('#receive_add_district option').filter(function () {
                    return $(this).html() == data.districtName; }).attr("selected", true);
            
            }
        }
	 });
}


function showOrderDetailFormat(value, row) {

    var escapeRow = $.openx.escapeHtml(JSON.stringify(row));

    //判断面单是否已打印
    var isPrint = (row.isPrint && row.isPrint === 1) ? true : false;

    var isCanPrint = (row.logisticsId && row.logisticsId != 'DADA' && row.logisticsId != 'FENGNIAO' && row.logisticsId != 'YIFENG' && row.logisticsId != 'MT' ) ? true : false; //表示能否打印

    var isShowNodeInfo=(row.logisticsId && row.logisticsId !='YIFENG') ? true : false ;

    var isDelivering = ((row.deliveryStatus && row.deliveryStatus == 'DELIVERING')) ? true : false;

    var isMTException = (row.logisticsId && row.logisticsId == 'MT' && row.deliveryStatus == 'DELIVERY_EXCEPTION')?true:false;
    
    /*是否显示投诉操作*/
    var isShowComplain = (row.logisticsId && row.logisticsId == 'DADA') ? true : false;
    
    var isModifyAddress = ((row.deliveryStatus && row.deliveryStatus == 'DELIVERY_CANCEL' ) && (row.deliveryType && row.deliveryType != 'REAL_TIME'))  ? true : false;

    //取消和异常的配送订单能进行重新发货操作 
    var isCannel = (row.deliveryStatus && (row.deliveryStatus == 'DELIVERY_CANCEL' || (row.deliveryStatus == 'DELIVERY_EXCEPTION' && row.logisticsId && row.logisticsId != 'MT') ) && row.orderIsCancel === 'N' ) ? true : false;

    var result;
    result = "<a href=\'javascript:void(0)\' onclick =\'javascript:showNodeInfo(" + escapeRow + ")\'><button type='button' "+(isShowNodeInfo ? '' : 'disabled')+" class='btn btn-outline " + (isShowNodeInfo ? 'btn-primary' : 'btn-default') + " btn-xs'>跟踪</button> <a>";

        result += "<a href=\'javascript:void(0)\' onclick =\'javascript:printer(\"preview\"," + (isCanPrint ? escapeRow : null) + ")\'>" +
            "<button type='button'" + (isCanPrint ? "" : "disabled") + "   class='btn btn-outline " + (isCanPrint ? 'btn-primary' : 'btn-default') + " btn-xs'>预览</button> "
        "<a>";

        result += "<a href=\'javascript:void(0)\' onclick =\'javascript:printer(\"print\"," + (isCanPrint ? escapeRow : null) + ")\'>" +
            "<button type='button'" + (isCanPrint ? "" : "disabled") + "   class='btn btn-outline " + (isCanPrint ? 'btn-primary' : 'btn-default')
            + " btn-xs'>" + (isPrint ? "<font color='#f7a54a'>重打</font>" : "打印") + "</button> "
        "<a>";

    //result += "<a href=\'javascript:void(0)\' onclick =\'javascript:markCanceled(" + escapeRow + ")\'>" +
      //  "<button type='button' " + (isDelivering ? "" : "disabled") + " class='btn btn-outline " + (isDelivering ? 'btn-primary' : 'btn-default') + " btn-xs'>配送异常</button> <a>";

        result += "<a href=\'javascript:void(0)\' onclick =\'javascript:markFinished(" + escapeRow + ")\'>" +
        "<button type='button' " + (isDelivering ? "" : "disabled") + " class='btn btn-outline " + (isDelivering ? 'btn-primary' : 'btn-default') + "  btn-xs'>配送完成</button> <a>";


        result += "<a href=\'javascript:void(0)\' onclick =\'javascript:cancelDeliveryTask(" + escapeRow + ")\'>" +
        "<button type='button' " + (isDelivering||isMTException ? "" : "disabled") + " class='btn btn-outline " + (isDelivering||isMTException ? 'btn-danger' : 'btn-default') + " btn-xs'>取消配送</button> <a>";

        result += "<a href=\'javascript:void(0)\' onclick =\'javascript:listPartner(" + escapeRow + ")\'>" +
        "<button type='button' " + (isCannel ? "" : "disabled") + " class='btn btn-outline " + (isCannel ? 'btn-success' : 'btn-default') + " btn-xs'>重新配送</button> <a>";

        // result += "<a href=\'javascript:void(0)\' onclick =\'javascript:problemWaybill(" + escapeRow + ")\'>" +
        // "<button type='button'  class='btn btn-outline btn-danger btn-xs'>问题标记</button><a>";

        result += "<a href=\'javascript:void(0)\' onclick =\'javascript:problemWaybill(" + escapeRow + ")\'>" +
        "<button type='button' class='btn btn-outline btn-danger btn-xs'>问题标记</button> <a>";
        
        result += "<a href=\'javascript:void(0)\' onclick =\'javascript:modifyAddress(" + escapeRow + ")\'>" +
        "<button type='button' " + (isModifyAddress ? "" : "disabled") + " class='btn btn-outline " + (isModifyAddress ? 'btn-success' : 'btn-default') + " btn-xs'>修改地址</button> <a>";
       if(isShowComplain){
            result += "<a href=\'javascript:void(0)\' onclick =\'javascript:logisticsComplain(" + escapeRow + ")\'>" +
                "<button type='button'  class='btn btn-outline btn-warning btn-xs'>投诉</button> <a>";
       }

    return result;
}


/**
* 问题运单格式化
 */
function problemWaybillFormatter(value, row) {
    return value === 'YES' ? "<font color='red' style='font-weight:bold'>是</font>" : "否"
}

/**
 * 问题运单标记
*/
function problemWaybill(row) {
    laytpl($.openx.innerHtml('problemWaybillTpl')).render(row, function (html) {
        $.openx.openLayer(['500', '340'], '问题运单记录', html, true, function () {
            var problemWaybillDesc = $("textarea[name='problemWaybillDesc']").val()
            if (problemWaybillDesc === '') {
                layer.msg("请填写问题描述。")
                return
            }

            var problemWaybill = $("#tableproblemWaybill").find("input[name='problemWaybill']:checked").val()

            if (problemWaybill === '') {
                layer.msg("请选择处理状态")
                return
            }
            $X("/logistics/logisticsListService", "problemWaybillHandle").callx({
                deliveryCode: row.deliveryCode,
                problemWaybill: problemWaybill,
                problemWaybillDesc: problemWaybillDesc,
                onResult: function (flag) {
                    if (flag) {
                        layer.closeAll()
                        $.openx.tableRefresh(null, null, true)
                    }
                },
                onError: function (error) {
                    layer.msg(error.msg);
                }
            });
        });
    });
}

function logisticsComplain(row) {
    $X("/logistics/logisticsListService", "getComplaintReasonsList").callx({
        orderCode: row.orderCode,
        onResult: function (data) {
            if(data != null){
                layer.closeAll('loading')
                var innerHtml = $.openx.innerHtml('logisticsComplainTpl');
                laytpl(innerHtml).render(data, function (html) {
                    var tpl = $.openx.openLayer(['auto', 'auto'], '物流投诉', html, false, function () {
                        if ($.openx.validation('logisticsComplainForm')) {
                            var complaintReasonId = $("#complainId").val();
                            $X("/logistics/logisticsListService", "doComplaint").callx({
                                orderCode: row.orderCode,
                                complaintReasonId: complaintReasonId,
                                onResult: function (result) {
                                    if(result){
                                        layer.closeAll();
                                        layer.alert("投诉成功，我们的客服美眉很快会联系您！");
                                    }else{
                                        layer.msg("投诉失败！");
                                    }
                                },
                                onError: function (error) {
                                    layer.msg(error.msg);
                                }
                            });
                        }
                    });
                });
            }else{
                layer.msg("获取投诉列表失败！");
            }
        },
        onError: function (error) {
            var res = JSON.parse(error);
            layer.msg(res.message)
        }
    });
}

//电子面单批量打印
function batchPrint() {
    var arrays = $.openx.getSelectedRow();
    if (arrays.length <= 0) {
        layer.msg('请选择需要打印的物流信息');
        return;
    } else {
        $.openx.confirm('确定批量打印？', function () {
            for (var o = 0; o < arrays.length; o++) {
                printer('print', arrays[o])
            }
        })
    }
}


// ******************以下代码接入菜鸟打印组件*******************************
var socket;
var printers = []; //全部的打印机组件
var defaultPrinter; //定义默认打印机
var currDefaultPrint;

var drive = [];
drive['YTO'] = "圆通打印机"
drive['ZTO'] = "中通打印机"
drive['SF'] = "顺丰打印机"
drive['JD'] = "京东打印机"
drive['YUNDA'] = "韵达打印机"

//连接客户端
function doConnect() {
    if (!socket) {
        socket = new WebSocket('ws://127.0.0.1:13528');
        // //如果是https的话，端口是13529 , socket = new WebSocket('wss://localhost:13529');
        socket.onopen = function (event) {
            console.log('客户端连接成功.');
            // 监听消息
            socket.onmessage = function (event) {
                var data = JSON.parse(event.data);
                console.log(data)
                if ("getPrinters" == data.cmd) {
                    printers = data.printers;//获取全部的打印机列表
                    defaultPrinter = data.defaultPrinter;//设置默认的打印机
                } else if (data && 'print' === data.cmd && data.previewImage) {//监听打印预览功能
                    window.open(data.previewImage[0])
                } else if (data && 'notifyPrintResult' === data.cmd && data.taskStatus === 'printed') {//监听是否打印完成
                    var printStatus = data.printStatus[0]
                    if (printStatus && printStatus.status === 'success') {
                        var deliveryCode = printStatus.documentID;
                        $X("/logistics/logisticsListService", "markPrintStatus").callx({
                            deliveryCode: deliveryCode,
                            onResult: function (data) {
                                $.openx.tableRefresh(null, null, true)
                                layer.closeAll()
                            }, onError: function (error) {

                            }
                        });


                    }
                }
            };
            // 监听Socket的关闭
            socket.onclose = function (event) {
                socket = new WebSocket('ws://127.0.0.1:13528');
            };

            socket.onerror = function (event) {
                layer.alert('连接菜鸟组件失败，请尝试刷新页面或重启菜鸟组件');
            };

        };
    } else {
        console.log('连接已打开无需重新创建');
    }
}


/***
  *
  * 获取请求的UUID，指定长度和进制,如
  * getUUID(8, 2)   //"01001010" 8 character (base=2)
  * getUUID(8, 10) // "47473046" 8 character ID (base=10)
  * getUUID(8, 16) // "098F4D35"。 8 character ID (base=16)
  *
  */
function getUUID(len, radix) {
    var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split('');
    var uuid = [], i;
    radix = radix || chars.length;
    if (len) {
        for (i = 0; i < len; i++) uuid[i] = chars[0 | Math.random() * radix];
    } else {
        var r;
        uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-';
        uuid[14] = '4';
        for (i = 0; i < 36; i++) {
            if (!uuid[i]) {
                r = 0 | Math.random() * 16;
                uuid[i] = chars[(i == 19) ? (r & 0x3) | 0x8 : r];
            }
        }
    }
    return uuid.join('');
}


//构造request对象
function getRequestObject(cmd) {
    var request = new Object();
    request.requestID = getUUID(8, 16);
    request.version = "1.0";
    request.cmd = cmd;
    return request;
}


//初始化打印机列表
function initPrinterList() {
    var request = getRequestObject('getPrinters');
    socket.send(JSON.stringify(request));
}


function printer(preview, row) {

    if (!socket) {
        doConnect()
    }
    if (!row) {
        return;
    }

    var printerName = drive[row.logisticsId]
    console.log("打印机列表：" + JSON.stringify(printers));
    for (var i = 0; i < printers.length; i++) {
        if (printers[i].name.indexOf(printerName) >= 0) {
            currDefaultPrint = printers[i].name;
            console.log("当前面单使用的打印机为：" + currDefaultPrint)
        }
    }

    if (printerName != currDefaultPrint && preview != 'preview') {
        layer.alert("请安装" + printerName + "驱动");
        return false;
    }

    var request = getRequestObject('print');
    request.task = {
        "taskID": getUUID(8, 10),
        "preview": preview && preview == 'preview' ? true : false,
        "previewType": "image",
        "printer": currDefaultPrint,
        "documents": []
    }
    //中通的接入
    $X("/logistics/logisticsListService", "getPrintInfo").callx({
        deliveryCode: row.deliveryCode,
        logisticsId: row.logisticsId,
        onResult: function (data) {

            console.log("打印模板基础地址：" + ecp_boss_logistics_tpl_url);

            var businessData;

            if (data) {
                data.deliveryCode = row.deliveryCode
            }

            if (row.logisticsId === 'ZTO') {

                businessData = getZtoBusinessData(data);
            }

            if (row.logisticsId === 'SF') {
                businessData = getSfBusinessData(data)
            }

            if (row.logisticsId === 'YTO') {
                businessData = getYtoBusinessData(data)
            }

            if (row.logisticsId === 'JD') {
                businessData = getJdBusinessData(data)
            }

            if (row.logisticsId === 'YUNDA') {
                businessData = getYunDaBusinessData(data)
            }

            request.task.documents.push(businessData);

            socket.send(JSON.stringify(request));

        }, onError: function (error) {
            var res = JSON.parse(error);
            layer.msg("打印失败原因：" + res.message)
        }
    });

}

doConnect();
setTimeout(function () { initPrinterList(); }, 1500)

//中通物流打印的业务数据
function getZtoBusinessData(data) {
    var businessData = {
        "documentID": data.deliveryCode,
        "contents": [{
            "data": {
                "recipient": {
                    "address": {
                        "detail": data.receiverAddress
                    },
                    "name": data.receiverName,
                    "phone": data.receiverPhone
                },
                "routingInfo": {
                    "consolidation": {
                        "name": data.packageCenterName
                    },
                    "sortation": {
                        "name": data.packageCenterCode
                    }
                },
                "sender": {
                    "address": {
                        "detail": data.sendAddress
                    },
                    "name": data.sendName,
                    "phone": data.sendPhone
                },
                pickSerialNumber: "#" + data.pickSerialNumber,
                "waybillCode": data.mailNo
            },
            "templateURL": ecp_boss_logistics_tpl_url + "/zto.json"
        }]
    }
    return businessData;
}

//得到顺丰的业务数据
function getSfBusinessData(data) {
    var businessData = {
        "documentID": data.deliveryCode,
        "contents": [{
            "data": {
                "recipient": {
                    "address": {
                        "detail": data.receiverAddress
                    },
                    "name": data.receiverName,
                    "phone": data.receiverPhone
                },
                "routingInfo": {
                    "consolidation": {
                        "name": data.packageCenterName
                    },
                    "sortation": {
                        "name": data.destCode
                    }
                },
                "sender": {
                    "address": {
                        "detail": data.sendAddress
                    },
                    "name": data.sendName,
                    "phone": data.sendPhone
                },
                "shippingOption": {
                    "services":
                        {
                            "TIMED-DELIVERY": { "value": "YYAXD" },
                            "PAYMENT-TYPE": { "value": "ON-DELIVERY" },
                            "SVC-INSURE": { "value": "" },
                            "SVC-COD":{"value":data.agencyFund}
                        }, "title": "E"
                },
                pickSerialNumber: "#" + data.pickSerialNumber,
                sfExpressCustId: "月结卡号:" + data.sfExpressCustId,
                "waybillCode": data.mailNo
            },
            "templateURL": ecp_boss_logistics_tpl_url + "/sf.json"
        }]
    }
    return businessData;
}


//获取圆通的打印数据
function getYtoBusinessData(data) {
    var businessData = {
        "documentID": data.deliveryCode,
        "contents": [{
            "data": {
                "recipient": {
                    "address": {
                        "detail": data.receiverAddress
                    },
                    "name": data.receiverName,
                    "phone": data.receiverPhone
                },
                "routingInfo": {
                    "consolidation": {
                        "name": data.packageCenterName
                    },
                    "sortation": {
                        "name": data.shortAddress
                    }

                },
                "sender": {
                    "address": {
                        "detail": data.sendAddress
                    },
                    "name": data.sendName,
                    "phone": data.sendPhone
                },
                pickSerialNumber: "#" + data.pickSerialNumber,
                "waybillCode": data.mailNo
            },
            "templateURL": ecp_boss_logistics_tpl_url + "/yto.json"
        }]
    }
    return businessData;
}

//获取京东物流的打印数据
function getJdBusinessData(data) {
    var obj = $.parseJSON(data.shortAddress);
    var businessData = {
        "documentID": data.deliveryCode,
        "contents": [{
            "data": {
                "recipient": {
                    "address": {
                        "detail": data.receiverAddress
                    },
                    "name": data.receiverName,
                    "phone": data.receiverPhone
                },
                "routingInfo": {
                    "sourcetSort": {
                        "sourcetSortCenterName": obj.sourcetSortCenterName,
                        "originalCrossCode": obj.originalCrossCode,
                        "originalTabletrolleyCode": obj.originalTabletrolleyCode
                    },
                    "targetSort": {
                        "targetSortCenterName": obj.targetSortCenterName,
                        "destinationCrossCode": obj.destinationCrossCode,
                        "destinationTabletrolleyCode": obj.destinationTabletrolleyCode
                    },
                    "siteName":obj.siteName,
                     "road":obj.road
                },
                "sender": {
                    "address": {
                        "detail": data.sendAddress
                    },
                    "name": data.sendName,
                    "phone": data.sendPhone
                },
                "pickSerialNumber": "#" + data.pickSerialNumber,
                "waybillCode": data.mailNo
            },
            "templateURL": ecp_boss_logistics_tpl_url + "/jd.json"
        }]
    }
    return businessData;
}


//获取韵达物流的打印数据
function getYunDaBusinessData(data) {
	var businessData = {
	        "documentID": data.deliveryCode,
	        "contents": [{
	            "data": {
	                "recipient": {
	                    "address": {
	                        "detail": data.receiverAddress
	                    },
	                    "name": data.receiverName,
	                    "phone": data.receiverPhone
	                },
	                "routingInfo": {
	                    "consolidation": {
	                        "name": data.packageCenterName
	                    },
	                    "sortation": {
	                        "name": data.destCode
	                    }
	                },
	                "sender": {
	                    "address": {
	                        "detail": data.sendAddress
	                    },
	                    "name": data.sendName,
	                    "phone": data.sendPhone
	                },
	                "shippingOption": {
	                    "services":
	                        {
	                            "TIMED-DELIVERY": { "value": "NEXT-DAY" },
	                            "PAYMENT-TYPE": { "value": "ON-DELIVERY" },
	                            "SVC-INSURE": { "value": "" }

	                        }, "title": "E"
	                },
	                pickSerialNumber: "#" + data.pickSerialNumber,
	                "waybillCode": data.mailNo
	            },
	            "templateURL": ecp_boss_logistics_tpl_url + "/yunda.json"
	        }]
	    }
    return businessData;
}